package com.dq.domain.record;

import com.dq.vo.baseVo.VO;

import com.dq.domain.org.Org;
import com.dq.domain.position.OrgPosition;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/11/20 0020 11:56:35
 */
@Data
@Entity
@ApiModel("员工变更记录")
public class StaffUserChangeRecord extends UserChangeRecord implements VO.ToVO{

    @ApiModelProperty("原来的岗位")
    @ManyToOne
    protected OrgPosition originalPosition;

    @ApiModelProperty("现在的岗位")
    @ManyToOne
    protected OrgPosition nowPosition;

    @ApiModelProperty("原来的门店")
    @ManyToOne
    protected Org originalOrg;

    @ApiModelProperty("现在的门店")
    @ManyToOne
    protected Org nowOrg;

    @ApiModelProperty("员工变更类型")
    @Enumerated(EnumType.ORDINAL)
    protected StaffUserChangeType staffUserChangeType;


    public enum StaffUserChangeType{
        quit("离职"),
        inTransfer("店内调岗"),
        outTransfer("跨店调岗");
        public String name;

        StaffUserChangeType(String name){
            this.name = name;
        }

    }

    @Data
    @ApiModel(value = "员工变更记录视图")
    public static class Vo implements VO {

    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        return vo;
    }

    @Data
    @ApiModel(value = "员工变更记录")
    public static class StaffUserChangeRecordVo{
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("所属门店")
        protected String orgName;
        @ApiModelProperty("门店id")
        protected Long orgId;
        @ApiModelProperty("员工工号")
        protected String cardNo;
        @ApiModelProperty("员工姓名")
        protected String userRealcName;
        @ApiModelProperty("变更类别")
        protected String type;
        @ApiModelProperty("变更类别")
        protected StaffUserChangeType typeEn;
        @ApiModelProperty("创建时间")
        protected String createTime;
        @ApiModelProperty("创建人")
        protected String createUserName;
    }

    public StaffUserChangeRecordVo toStaffUserChangeRecordVo(){
        StaffUserChangeRecordVo vo = new StaffUserChangeRecordVo();
        vo.id = fmt(this.id);
        vo.orgName = this.originalOrg != null ? fmt(this.originalOrg.getSimpleName()):"";
        vo.orgId = this.originalOrg != null ? fmt(this.originalOrg.getId()):null;
        vo.cardNo = fmt(this.sysUser.getCardNo());
        vo.userRealcName = fmt(this.sysUser.getUserRealcName());
        vo.type = fmt(this.staffUserChangeType.name);
        vo.createTime = fmt(this.createTime,TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserName = this.createUser != null ? fmt(this.createUser.getUserRealcName()):"";
        return vo;
    }
}
